package com.dt76.smallloanbackendservice.controller.etao;

import com.dt76.smallloanbackendservice.pojo.etao.CurrentUser;
import com.dt76.smallloanbackendservice.pojo.etao.Department;
import com.dt76.smallloanbackendservice.pojo.etao.Employee;
import com.dt76.smallloanbackendservice.service.etao.DepartmentService;
import com.dt76.smallloanbackendservice.utils.Page;
import com.dt76.smallloanbackendservice.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class DepartmentController {

    @Autowired
    DepartmentService departmentService;

    @RequestMapping("/deptSelectAll")
    @ResponseBody
    public Page getAllDept(@RequestParam Integer pageNum) {
        return departmentService.getAllDept(pageNum);
    }

    @RequestMapping("/getDept")
    @ResponseBody
    public List<Department> getDept() {
        return departmentService.getDept();
    }


    @RequestMapping("/getDeptById")
    @ResponseBody
    public Department getDetpById(@RequestParam Integer did) {
        return departmentService.getDetpById(did);
    }

    @RequestMapping("/delDeptById")
    @ResponseBody
    public Result delDeptById(@RequestParam Integer did,@RequestBody CurrentUser currentUser) {
        Result result = new Result();
        result.setSuccess(departmentService.delDeptById(did,currentUser));
        return result;
    }

    @RequestMapping("/updDeptEnable")
    @ResponseBody
    public Result updDeptEnable(@RequestParam Integer did, @RequestParam Integer enable) {
        Result result = new Result();
        result.setSuccess(departmentService.updDeptEnable(did, enable));
        return result;
    }


    @RequestMapping(value = "/addDept", method = RequestMethod.POST)
    @ResponseBody
    public Result addDept(@RequestBody Department department,@RequestParam Integer currentId) {
        Result result = new Result();
        result.setSuccess(departmentService.addNewDept(department,currentId));
        return result;
    }

    @RequestMapping(value = "/updDept", method = RequestMethod.PUT)
    @ResponseBody
    public Result updDept(@RequestBody Department department,@RequestParam Integer currentId) {
        Result result = new Result();
        result.setSuccess(departmentService.updDept(department,currentId));
        return result;
    }
}
